home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’87 / Source ƒ.sit / Source ƒ / emacs source ƒ / ANSI.C next >
Encoding:
C/C++ Source or Header  |  1992-06-28  |  4.4 KB  |  238 lines  |  [TEXT/MARC]

  1. /*
  2.  * The routines in this file provide support for ANSI style terminals
  3.  * over a serial line. The serial I/O services are provided by routines in
  4.  * "termio.c". It compiles into nothing if not an ANSI device.
  5.  */
  6.  
  7. #define    termdef    1            /* don't define "term" external */
  8.  
  9. #include        <stdio.h>
  10. #include    "estruct.h"
  11. #include        "edef.h"
  12.  
  13. #if     ANSI
  14.  
  15. #if    AMIGA
  16. #define NROW    23                      /* Screen size.                 */
  17. #define NCOL    77                      /* Edit if you want to.         */
  18. #else
  19. #define NROW    25                      /* Screen size.                 */
  20. #define NCOL    80                      /* Edit if you want to.         */
  21. #endif
  22. #define    NPAUSE    100            /* # times thru update to pause */
  23. #define    MARGIN    8            /* size of minimim margin and    */
  24. #define    SCRSIZ    64            /* scroll size for extended lines */
  25. #define BEL     0x07                    /* BEL character.               */
  26. #define ESC     0x1B                    /* ESC character.               */
  27.  
  28. extern  int     ttopen();               /* Forward references.          */
  29. extern  int     ttgetc();
  30. extern  int     ttputc();
  31. extern  int     ttflush();
  32. extern  int     ttclose();
  33. extern  int     ansimove();
  34. extern  int     ansieeol();
  35. extern  int     ansieeop();
  36. extern  int     ansibeep();
  37. extern  int     ansiopen();
  38. extern    int    ansirev();
  39. extern    int    ansiclose();
  40. extern    int    ansikopen();
  41. extern    int    ansikclose();
  42.  
  43. #if    COLOR
  44. extern    int    ansifcol();
  45. extern    int    ansibcol();
  46.  
  47. int    cfcolor = -1;        /* current forground color */
  48. int    cbcolor = -1;        /* current background color */
  49. #endif
  50.  
  51. /*
  52.  * Standard terminal interface dispatch table. Most of the fields point into
  53.  * "termio" code.
  54.  */
  55. TERM    term    = {
  56.         NROW-1,
  57.         NCOL,
  58.     MARGIN,
  59.     SCRSIZ,
  60.     NPAUSE,
  61.         ansiopen,
  62.         ansiclose,
  63.     ansikopen,
  64.     ansikclose,
  65.         ttgetc,
  66.         ttputc,
  67.         ttflush,
  68.         ansimove,
  69.         ansieeol,
  70.         ansieeop,
  71.         ansibeep,
  72.     ansirev
  73. #if    COLOR
  74.     , ansifcol,
  75.     ansibcol
  76. #endif
  77. };
  78.  
  79. #if    COLOR
  80. ansifcol(color)        /* set the current output color */
  81.  
  82. int color;    /* color to set */
  83.  
  84. {
  85.     if (color == cfcolor)
  86.         return;
  87.     ttputc(ESC);
  88.     ttputc('[');
  89.     ansiparm(color+30);
  90.     ttputc('m');
  91.     cfcolor = color;
  92. }
  93.  
  94. ansibcol(color)        /* set the current background color */
  95.  
  96. int color;    /* color to set */
  97.  
  98. {
  99.     if (color == cbcolor)
  100.         return;
  101.     ttputc(ESC);
  102.     ttputc('[');
  103.     ansiparm(color+40);
  104.     ttputc('m');
  105.         cbcolor = color;
  106. }
  107. #endif
  108.  
  109. ansimove(row, col)
  110. {
  111.         ttputc(ESC);
  112.         ttputc('[');
  113.         ansiparm(row+1);
  114.         ttputc(';');
  115.         ansiparm(col+1);
  116.         ttputc('H');
  117. }
  118.  
  119. ansieeol()
  120. {
  121.         ttputc(ESC);
  122.         ttputc('[');
  123.         ttputc('K');
  124. }
  125.  
  126. ansieeop()
  127. {
  128. #if    COLOR
  129.     ansifcol(gfcolor);
  130.     ansibcol(gbcolor);
  131. #endif
  132.         ttputc(ESC);
  133.         ttputc('[');
  134.         ttputc('J');
  135. }
  136.  
  137. ansirev(state)        /* change reverse video state */
  138.  
  139. int state;    /* TRUE = reverse, FALSE = normal */
  140.  
  141. {
  142. #if    COLOR
  143.     int ftmp, btmp;        /* temporaries for colors */
  144. #endif
  145.  
  146.     ttputc(ESC);
  147.     ttputc('[');
  148.     ttputc(state ? '7': '0');
  149.     ttputc('m');
  150. #if    COLOR
  151.     if (state == FALSE) {
  152.         ftmp = cfcolor;
  153.         btmp = cbcolor;
  154.         cfcolor = -1;
  155.         cbcolor = -1;
  156.         ansifcol(ftmp);
  157.         ansibcol(btmp);
  158.     }
  159. #endif
  160. }
  161.  
  162. ansibeep()
  163. {
  164.         ttputc(BEL);
  165.         ttflush();
  166. }
  167.  
  168. ansiparm(n)
  169. register int    n;
  170. {
  171.         register int q,r;
  172.  
  173.         q = n/10;
  174.         if (q != 0) {
  175.         r = q/10;
  176.         if (r != 0) {
  177.             ttputc((r%10)+'0');
  178.         }
  179.         ttputc((q%10) + '0');
  180.         }
  181.         ttputc((n%10) + '0');
  182. }
  183.  
  184. ansiopen()
  185. {
  186. #if     V7 | USG | BSD
  187.         register char *cp;
  188.         char *getenv();
  189.  
  190.         if ((cp = getenv("TERM")) == NULL) {
  191.                 puts("Shell variable TERM not defined!");
  192.                 exit(1);
  193.         }
  194.         if (strcmp(cp, "vt100") != 0) {
  195.                 puts("Terminal type not 'vt100'!");
  196.                 exit(1);
  197.         }
  198. #endif
  199.     revexist = TRUE;
  200.         ttopen();
  201. }
  202.  
  203. ansiclose()
  204.  
  205. {
  206. #if    COLOR
  207.     ansifcol(7);
  208.     ansibcol(0);
  209. #endif
  210.     ttclose();
  211. }
  212.  
  213. ansikopen()    /* open the keyboard (a noop here) */
  214.  
  215. {
  216. }
  217.  
  218. ansikclose()    /* close the keyboard (a noop here) */
  219.  
  220. {
  221. }
  222.  
  223. #if    FLABEL
  224. fnclabel(f, n)        /* label a function key */
  225.  
  226. int f,n;    /* default flag, numeric argument [unused] */
  227.  
  228. {
  229.     /* on machines with no function keys...don't bother */
  230.     return(TRUE);
  231. }
  232. #endif
  233. #else
  234. ansihello()
  235. {
  236. }
  237. #endif
  238.